﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SPA_Prototype.Model
{
    class RoomManagement
    {
        private DatabaseDataSet _Dataset;
        private DatabaseDataSet.RoomTableDataTable _DataTable;
        private DatabaseDataSetTableAdapters.RoomTableTableAdapter _Adt;

        // contructor
        public RoomManagement(DatabaseDataSet dt)
        {
            _Dataset = dt;
            _DataTable = _Dataset.RoomTable;
            _Adt = new DatabaseDataSetTableAdapters.RoomTableTableAdapter();

            LoadDB();
        }

        // medthod : update and load
        public bool IsVIPRoom(string roomName)
        {
            bool results = false;
            int count = _DataTable.Rows.Count;
            for (int j = 0; j < count; j++)
                if (_DataTable[j].Name == roomName)
                {
                    if (_DataTable[j].VIP == true) results = true;
                    break;
                }
            return results;
        }
        public int RoomCharge(string roomName)
        {
            int result = 0;
            int count = _DataTable.Rows.Count;
            for(int j = 0;j<count;j++)
                if (_DataTable[j].Name == roomName)
                {
                    result = _DataTable[j].Charge;
                    break;
                }
            return result;
        }

        private void LoadDB()
        {
            _Adt.Fill(_DataTable);
        }

        public void UpdateDB()
        {
            try
            {
                _Adt.Update(_DataTable);
                MessageBox.Show("Room update successfully !", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
